module.exports = (secret) => {
  return async function jwtErr(ctx, next) {
    const token = ctx.request.header.authorization;
    let decode;
    // 判断是否有携带token
    // eslint-disable-next-line eqeqeq
    if (token == 'null' && !token) {
      ctx.status = 200;
      ctx.body = {
        code: 401,
        msg: 'token不存在',
      };
      return;
    }
    try {
      decode = ctx.app.jwt.verify(token, secret);
      await next();
    } catch (error) {
      ctx.status = 200;
      ctx.body = {
        msg: 'token已过期，请重新登录',
        code: 401,
      };
      return;
    }

  };
};
